package com.springinaction.ch05.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;


/**
 * @author ssk
 * @Title: WebConfig
 * @ProjectName SpringInAction
 * @Description: TODO
 * @date 18-12-7下午9:24
 */

@Configuration
@ComponentScan({"com.springinaction.ch05.web"})
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
      @Bean
      /**
      　* @Description: viewResolver视图解析器 配置视图解析器，名为home的视图将被解析为/WEB-INF/views/home.jsp(Prefix + home+Suffix)
      　* @param []
      　* @return org.springframework.web.servlet.ViewResolver
      　* @throws
      　* @date 18-12-7 下午9:44
      　*/
      public ViewResolver viewResolver() {
          InternalResourceViewResolver resolver = new InternalResourceViewResolver();
          resolver.setPrefix("/ch05/");
          resolver.setSuffix(".jsp");
          resolver.setExposeContextBeansAsAttributes(true);
          return resolver;

      }

    @Override
    /**
    　* @Description: 配置静态文件处理方式 此配置要求DispatcherServlet将对静态资源的请求转发到Servlet容器中默认的Servlet上
        而非使用DispatcherServlet本身来处理此类请求
    　* @param [configurer]
    　* @return void
    　* @throws 
    　* @date 18-12-7 下午9:45
    　*/
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
           configurer.enable();
          //super.configureDefaultServletHandling(configurer);
    }
}
